<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/4/19
 * Time: 9:24
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\index\controller;

use app\BaseController;
use app\common\lib\Show;
use app\common\lib\Status;
use app\common\model\MallCate;

class Goods extends BaseController
{
    public function GoodsByCate()
    {
        //获取所有分类
        if (!$this->request->isGet()) {
            return Show::json_diy(Status::mini_error,"请求类型错误");
        }
        //获取分类
        try {
            $menu = (new MallCate())->getMallCateByPidList(0,'id as type ,title as name');
        } catch (\Exception $e) {
            return Show::json_diy(Status::mini_error,"分类异常");
        }

        return Show::json_diy(1,"ok",$menu);
    }
    public function GoodsCateById(){

        if(!$this->request->isGet()){
            return Show::json_diy(Status::mini_error,"请求类型错误");
        }
        $cate_id = $this->request->param('cate_id',0,'intval');
        if($cate_id === 0){
            return Show::json_diy(Status::mini_error,"内部异常");
        }
        try {
            $menu = (new MallCate())->getMallCateByPidList($cate_id,'id as type ,title as name');
        } catch (\Exception $e) {
            return Show::json_diy(Status::mini_error,"分类异常");
        }
    }
}